<template>
  <div id="app">
    <router-view/>
  </div>
</template>


<script>
import { jwtDecode } from 'jwt-decode';
export default {
    name: 'App',
    created() {
      //判断token是否存在，如果存在，则解析token获取用户信息，并保存到状态中
      const token = localStorage.getItem('token');
      if (token) {
        const decoded = jwtDecode(token);
        this.$store.dispatch('setUser', decoded);
        this.$store.dispatch('setIsAuthenticated',!this.isEmpty(decoded));
      }
    },
    methods: {      
      isEmpty(value){
        return (value === undefined ||
        value === null ||
        (typeof value === "object" && Object.keys(value).length === 0) ||
        (typeof value === "string" && value.trim().length === 0))
      }
    }
}
</script>

<style>
html,body,
#app {
  height: 100%;
  width: 100%;
}
</style>
